﻿using System.Linq;
using Renren.Helpers;
using Renren.Models;

namespace Renren.ViewModels
{
    public class UserViewModel : ViewModel
    {
        private UserModel _user;
        public UserModel User
        {
            get { return _user; }
            set
            {
                NotifyPropertyChanged("User");
                _user = value;

                StatusContent = _user.StatusContent.Trim(33);
                StatusTime = _user.StatusTime.GetFriendlyTime();
                Hometown = _user.Province + " " + _user.City;

                string date = "";
                if (_user.BirthYear.Split('后').Count() == 1)
                {
                    if (_user.BirthYear != "0")
                    {
                        date += _user.BirthYear;
                        if (_user.BirthMonth != "0" && _user.BirthDay != "0")
                        {
                            date += "-" + _user.BirthMonth + "-" + _user.BirthDay;
                        }
                    }
                    else
                    {
                        if (_user.BirthMonth != "0" && _user.BirthDay != "0")
                        {
                            date += _user.BirthMonth + "-" + _user.BirthDay;
                        }
                    }
                }
                else
                {
                    date = _user.BirthYear;
                }
                Birthday = date;
            }
        }

        private string _statusContent;
        public string StatusContent
        {
            get { return _statusContent; }
            private set
            {
                if (value != _statusContent)
                {
                    _statusContent = value;
                    NotifyPropertyChanged("StatusContent");
                }
            }
        }

        private string _statusTime;
        public string StatusTime
        {
            get { return _statusTime; }
            private set
            {
                if (value != _statusTime)
                {
                    _statusTime = value;
                    NotifyPropertyChanged("StatusTime");
                }
            }
        }
        
        private string _birthday;
        public string Birthday
        {
            get { return _birthday; }
            private set
            {
                if (value != _birthday)
                {
                    _birthday = value;
                    NotifyPropertyChanged("Birthday");
                }
            }
        }

        private string _hometown;
        public string Hometown
        {
            get { return _hometown; }
            private set
            {
                if (value != _hometown)
                {
                    _hometown = value;
                    NotifyPropertyChanged("Hometown");
                }
            }
        }
        
        public override long Id
        {
            get { return User.Id; }
        }

        public override void Update(Model model)
        {
            this.User = model as UserModel;
        }
    }
}
